$(function() {
	expendGroup = 1;
	getExpendGroup()
})

function getExpendGroup(){
	const currYear = localStorage.getItem("year");
	const currMon = localStorage.getItem("month");
	const currDept = localStorage.getItem("dept");
	$.get(
	  `${API_URL}getdata?budgetYear=${currYear}&budgetMonth=${currMon}&status=2&chartPage=60301&chartNo=3&username=${getUsername}`,
	  {},
	  function (res) {
		  console.log(res)
		  let re = eval("(" + res + ")");
		  console.log(re)
		  getCompose(re.items[0].charts[0].data[0])
	  }
	)
	$.get(
	  `${API_URL}getdata?budgetYear=${currYear}&budgetMonth=${currMon}&status=2&chartPage=60301&chartNo=1&username=${getUsername}`,
	  {},
	  function (res) {
		  console.log(res)
		  let re = eval("(" + res + ")");
		  console.log(re)
		  getExecute(re.items[0].charts[0].data[0])
	  }
	)
	$.get(
	  `${API_URL}getdata?budgetYear=${currYear}&budgetMonth=${currMon}&status=2&chartPage=60301&chartNo=2&username=${getUsername}`,
	  {},
	  function (res) {
		  console.log(res)
		  let re = eval("(" + res + ")");
		  console.log(re)
		  getRecoveries(re.items[0].charts[0].data[0])
	  }
	)
}

function getCompose(data) {
	console.log(data)
	$('.compose-word').html(`<div class="">
									<p>本月发生总额</p>
									<h2>${FormatWYCash(data.key01)}<span>万元</span></h2>
									<div class="contrast">
										<div class="${data.key02>0?'rise':data.key02==0?'fair':'drop'}">
											<img src="${data.key02>0?'assets/images/departmental-charge/arrow-up-filling.svg':data.key02==0?'assets/images/departmental-charge/icon-pingjun@2x.png':'assets/images/departmental-charge/arrow-down-filling.svg'}" >
											<span>${(data.key02 * 100).toFixed(1)}%</span>
										</div>
										<p>较上月</p>
									</div>
								</div>
								<ul>
									<li>
										<p>纵向开支</p>
										<h4>${(data.key03 * 100).toFixed(1)}%</h4>
									</li>
									<li>
										<p>部门研制费</p>
										<h4>${(data.key04 * 100).toFixed(1)}%</h4>
									</li>
									
									<li>
										<p>横向开支</p>
										<h4>${(data.key06 * 100).toFixed(1)}%</h4>
									</li>
									<li>
										<p>部门管理费</p>
										<h4>${(data.key07 * 100).toFixed(1)}%</h4>
									</li>
								</ul>`)
								// <li>
								// 	<p>部门工资</p>
								// 	<h4>${(data.key05 * 100).toFixed(1)}%</h4>
								// </li>
	let seriesData = [{
			value: (data.key03 * 100).toFixed(1),
			name: '纵向开支'
		},
		{
			value: (data.key04 * 100).toFixed(1),
			name: '部门研制费'
		},
		// {
		// 	value: (data.key05 * 100).toFixed(1),
		// 	name: '部门工资'
		// },
		{
			value: (data.key06 * 100).toFixed(1),
			name: '横向开支'
		},
		{
			value: (data.key07 * 100).toFixed(1),
			name: '部门管理费'
		},
	];
	const colorList = ['#165DFF', '#50CD89', '#722ED1', '#FD7E14', '#0DCAF0'];
	have("compose-chart") ? quansuozhichuPie("compose-chart", colorList, seriesData) : "";
}

function getExecute(re){
	let zhichuData = [];
	let legendData = [''];
	let xData = ['预计签约','完成情况'];
	zhichuData.push(FormatWYCash(re.key01));
	zhichuData.push(FormatWYCash(re.key02));
	
	let seriesData = [{
		name: "金额",
		barWidth: "50%",
		type: "bar",
		data: zhichuData,
		itemStyle: {
			color: "#165DFF",
		},
		label: {
			show: true,
			position: 'top',
			fontSize: 12,
			color: "#1D2129",
			fontWeight: 600,
		},
	}];
	have("executeDetail") ? monthTrend("executeDetail", seriesData, legendData, xData, 123) : "";
}

function getRecoveries(re){
	let zhichuData = [];
	let legendData = [''];
	let xData = ['预计回款','完成情况'];
	zhichuData.push(FormatWYCash(re.key01));
	zhichuData.push(FormatWYCash(re.key02));
	
	let seriesData = [{
		name: "金额",
		barWidth: "50%",
		type: "bar",
		data: zhichuData,
		itemStyle: {
			color: "#165DFF",
		},
		label: {
			show: true,
			position: 'top',
			fontSize: 12,
			color: "#1D2129",
			fontWeight: 600,
		},
	}];
	have("recoveriesDetail") ? monthTrend("recoveriesDetail", seriesData, legendData, xData, 123) : "";
}